package com.zhixianggou.caibaobox.commons.exp;

import com.zhixianggou.caibaobox.commons.result.ReturnCodeEnum;
import com.zhixianggou.caibaobox.commons.result.ReturnData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice

public class GlobalExceptionHandler {

    /**
     * 默认全局异常处理
     * @param e
     * @return
     */
    @ExceptionHandler({RuntimeException.class,Exception.class})
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ReturnData<String> handleException(Exception e){
        log.error("######Come In GlobalExceptionHandler######");
        log.error("系统异常:{}",e.getMessage());
        return ReturnData.fail(ReturnCodeEnum.RC500.getCode(),e.getMessage());
    }
}
